// ActionScript file
import flash.events.MouseEvent;

import mx.containers.Canvas;
import mx.controls.Button;
import mx.controls.Label;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

/**
 * 发送HTTPService 
 * @param String url HTTP Serivce的地址
 * @param Object param 参数
 * @param Function Callback 加调函数，这里用来执行失败操作
 * 
 */
private function SendHttpService( url:String, param:Object = null, Callback:Function = null, name:String='' ):void
{
	var httpServiceObj:HTTPService = new HTTPService();
	httpServiceObj.resultFormat = "e4x";
	httpServiceObj.method = "POST";
	httpServiceObj.url = url;
	httpServiceObj.addEventListener(FaultEvent.FAULT, function(event:FaultEvent):void{doFault(event,name)} );
	httpServiceObj.addEventListener(ResultEvent.RESULT, Callback );
	httpServiceObj.send(param);
}

/**
 * HTTPService失败时的事件
 */ 
private function doFault(event:FaultEvent, name:String):void{
	trace(name+' is Fault.');
	//Alert.show(this.flagScreen.toString());
	//event.target.sent();
	ss.setLabel(name+'失败…… ');
	Alert.show(name+'fault');
	//Alert.show(event.toString());
}

/**
 * calendar HTTPService成功
 * 
 */
private function CalendarRPCResult(event:ResultEvent):void
{
	
	for each (var s:XML in event.result.info)
	{
		Calendars.addItem({name: s.name, urlx: s.urlx,urls: s.urls, width:s.width, height:s.height});
	}
	ss.setLabel('加载日历完成');
	this.HTTPSeCalendar = true;
	trace('calendar @ '+this.flagScreen.toString());
	removeSplash();
}

/**
 * 读取用户上传的图片
 * @param event:ResultEvent
 */
private function getMyPhotoRPCResult(event:ResultEvent):void{
	trace(event.result);
	var tmp:Array=new Array();
	for each (var s:XML in event.result.info)
	{
		//trace(s.name);
		tmp.push({name: s.name, urlx: s.urlx, width:s.width, height:s.height});
		//myphoto.addItem({name: s.name, urlx: s.urlx});
	}
	//tmp.push({name: 's.name', urlx: 's.urlx'});
	//tmp.push({name: 's.name', urlx: 's.urlx'});
	//Alert.show(event.toString());
	if(tmp.length > 0){
		if(tmp[0].name == 'NOLOGIN'){
			Alert.show('您尚未登录，请登录后再试。', '提示', Alert.OK, null, function ():void{gotologin(tmp[0].urlx);});
			return ;
			
		}else{
			for(var t:String in tmp){
				myphoto.addItem({name:tmp[t].name, urlx:tmp[t].urlx, width:tmp[t].width, height:tmp[t].height});
				//Alert.show(tmp[t].urlx);
			}
			myphotos.dataProvider = myphoto;
		}
		
	}else{
		var can1:Canvas = new Canvas();
		can1.id = 'temp1'
		can1.name = 'temp1';
		can1.x = 0;
		can1.y = 0;
		can1.percentWidth = 100;
		can1.percentHeight = 100;
		can1.setStyle('color', '#000000');
		var tL:Label = new Label();
		tL.text = '您还没有上传自己的照片';
		tL.y = 88;
		tL.setStyle('horizontalCenter', '0');
		//tL.setStyle('verticalCenter', '0');
		can1.addChild(tL);
		var tB:Button = new Button();
		tB.label = '上传照片';
		tB.setStyle('horizontalCenter', '0');
		tB.y = 140;
		tB.addEventListener(MouseEvent.CLICK, ShowUploadMyPhotoDialog);
		can1.addChild(tB);
		myphotoCanvas.addChild(can1);
	}
	
	trace('用户照片加载完毕');
	ss.setLabel('读取照片完成');
	this.HTTPSeMyPhoto = true;
	trace('calendar @ '+this.flagScreen.toString());
	removeSplash();
	
}
/**
 * Maked HTTPService成功
 * 
 */
private function MakedRPCResult(event:ResultEvent):void
{
	
	for each (var s:XML in event.result.info)
	{
		mymaked.addItem({name: s.name, urlx: s.urlx,urls: s.urls, width:s.width, height:s.height});
	}
	//mymakes.dataProvider = mymaked;
	
	trace('Load Maked @ Done');
	
}
